package com.sinoglobal.sinostore.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sinoglobal.sinostore.R;
import com.sinoglobal.sinostore.bean.CommentVo;

/***
 * 
* @title: PublicConsultAdapter.java 
* @package com.chiliring.sinostore.adapter 
* @description: TODO(发表咨询列表) 
* @author LK
* @date 2015-1-15 下午2:00:56
 */
public class PublicConsultAdapter extends BaseAdapter {
	private Context context;
	private List<CommentVo> data;

	public PublicConsultAdapter(Context context,ArrayList<CommentVo> arrayList){
		this.context = context;
		this.data = arrayList;
	}
	
	public void clearData(){
		if(null != data){
			this.data.clear();
		}
		notifyDataSetChanged();
	}
	
	/**添加数据**/
	public void addData(ArrayList<CommentVo> arrayList){
		if(null != arrayList){
			this.data.addAll(arrayList);
		}
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		if(null == this.data){
			return 0;
		}else{
			return this.data.size();
		}
		
	}

	@Override
	public Object getItem(int postion) {
		return this.data.get(postion);
	}

	@Override
	public long getItemId(int positon) {
		return positon;
	}

	@Override
	public View getView(int postion, View convertView, ViewGroup arg2) {
		if(null == convertView){
			convertView = LayoutInflater.from(context).inflate(R.layout.shop_activity_consultlist_item, null);
		}
		//咨询时间
		TextView time = ViewHolder.getViewById(convertView, R.id.time);
		//发表咨询人
		TextView person = ViewHolder.getViewById(convertView, R.id.person_name);
		//咨询为题
		TextView question = ViewHolder.getViewById(convertView, R.id.question);
		//回答
		TextView answer = ViewHolder.getViewById(convertView, R.id.answer);
		CommentVo entity = (CommentVo) getItem(postion);
		time.setText(entity.getCreate_time());
		person.setText(entity.getNike_name());
		question.setText(entity.getMessage());
		answer.setText(entity.getReply());
		return convertView;
	}

}
